﻿using System;
using System.Data;
using System.Text;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Util
{
    public static class JavascriptHelper
    {
        public static void Alert(string message, Page page)
        {
            ScriptManager.RegisterClientScriptBlock(page, typeof(Page), "Uyari", "alert('" + message + "');", true);
        }

        public static void ErrorPage(string message, Page page)
        {
            ScriptManager.RegisterClientScriptBlock(page, typeof(Page), "ErrorPage", "", true);
        }

        public static void RunCustomJs(string script, Page page)
        {
            ScriptManager.RegisterClientScriptBlock(page, typeof(Page), "CustomJs", script, true);
        }

        public static void RunJsMethod(string methodName, string _params, Page page)
        {
            ScriptManager.RegisterClientScriptBlock(page, typeof(Page), "Method", methodName + "(" + _params + ");", true);
        }

        public static void RunJsMethod(string methodName, Page page)
        {
            ScriptManager.RegisterClientScriptBlock(page, typeof(Page), "Method", methodName + "();", true);
        }

        public static void RunParentPageJsMethod(string methodName, string _params, Page page)
        {
            ScriptManager.RegisterClientScriptBlock(page, typeof(Page), "ParentMethod", "window.parent." + methodName + "(" + _params + ");", true);
        }

        public static void RunParentPageJsMethod(string methodName, Page page)
        {
            ScriptManager.RegisterClientScriptBlock(page, typeof(Page), "ParentMethod", "window.parent." + methodName + "();", true);
        }

        public static void RunPopUpCloseAndRefreshMethod(Page page)
        {
            ScriptManager.RegisterClientScriptBlock(page, typeof(Page), "ParentCloseAndRefreshMethod", "window.parent.PopUpCloseRefresh();", true);
        }

        public static void RunPopUpCloseMethod(Page page)
        {
            ScriptManager.RegisterClientScriptBlock(page, typeof(Page), "ParentMethod", "self.parent.tb_remove();", true);
        }

        public static string ScriptTaglariArasinaAl(string pYazi)
        {
            return string.Format("<script type=\"text/javascript\">\r\n " +
                    " <!--\r\n " +
                    " {0}\r\n " +
                    "// -->\r\n " +
                    "</script>", pYazi);
        }
    }
}